package com.weetop.cfw.base.presenter.imp

import com.blankj.utilcode.util.AppUtils
import com.weetop.cfw.MainActivity
import com.weetop.cfw.base.presenter.MainPresenter
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.base.view.MainView
import com.weetop.cfw.bean.AppVersionBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class MainPresenterImp(var mainView: MainView? = null):MainPresenter {


    /**
     * 检查APP版本信息
     */
    override fun checkAppVersionInfo(mainActivity: MainActivity) {
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().checkAppVersionInfo(AppUtils.getAppVersionCode()),mainActivity,object:RxJavaCallBack<AppVersionBean>(){

            override fun onSuccess(t: AppVersionBean?) {
                mainView?.appVersionInfoGetSuccess(t)
            }

        })
    }


    override fun attachView(baseView: BaseView) {
        mainView = baseView as? MainView
    }

    override fun detachView() {
        mainView = null
    }
}